sysdir set PERSONAL "I:\MAA2015-20 Credit and Education\stata"
do "I:\MAA2015-20 Credit and Education\stata\outreg2.ado"
do "I:\MAA2015-20 Credit and Education\stata\rdrobust.ado"

use "basesample_earn.dta",clear
set more off
set matsize 10000

*Table 1 summary statistics

reg ratio_pass age female maori white disable full uni business science loan_amt decile loan enrol ba_5yr ba_7yr
outreg2 using table1, excel dec(2) cttop(all) sum replace

reg ratio_pass age female maori white disable full uni business science loan_amt decile loan enrol ba_5yr ba_7yr if ratio_pass>=0.35&ratio_pass<=0.65
outreg2 using table1, excel dec(2) cttop(all) sum  

reg ratio_pass age female maori white disable full uni business science loan_amt decile loan enrol ba_5yr ba_7yr if ratio_pass>=0.35&ratio_pass<=0.65&treat==1
outreg2 using table1, excel dec(2) cttop(all) sum  

reg ratio_pass age female maori white disable full uni business science loan_amt decile loan enrol ba_5yr ba_7yr if ratio_pass>=0.35&ratio_pass<=0.65&treat==0
outreg2 using table1, excel dec(2) cttop(all) sum  

reg ratio_pass percent 
outreg2 using table1, excel dec(2) cttop(all) sum 

reg ratio_pass percent if ratio_pass>=0.35&ratio_pass<=0.65 
outreg2 using table1, excel dec(2) cttop(all) sum  

reg ratio_pass percent if ratio_pass>=0.35&ratio_pass<=0.65&treat==1
outreg2 using table1, excel dec(2) cttop(all) sum  

reg ratio_pass percent if ratio_pass>=0.35&ratio_pass<=0.65&treat==0
outreg2 using table1, excel dec(2) cttop(all) sum  


*Table 2

forv i = 0(1)1 {
 
rdrobust loan ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using table2,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

foreach y of varlist enrol ba_5yr ba_7yr {

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using table2, excel dec(2) 

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using table2, excel dec(2) 

}
}

*Table 3

forv i = 1(1)1 {

rdrobust loan ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using table3,excel dec(2) 

forv l = 1(1)5 {

foreach y of varlist ba_post`l'yr {

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using table3,excel dec(2) 

rdrobust `y'  ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using table3,excel dec(2) 

}
}
}

*Left panel, female students assessed in 2010
preserve
keep if year == 2010

forv i = 1(1)1 {

rdrobust loan ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008)
outreg2 using table3,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 
 
forv l = 1(1)7 {
 
foreach y of varlist ba_post`l'yr {

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008)
outreg2 using table3,excel dec(2)  

rdrobust `y'  ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008)
outreg2 using table3,excel dec(2)  

}
}
}
restore

* Table 4
forv i = 1(1)1 {
forv l = 0(1)5 {
 
foreach y of varlist avg_was_post`l'yr was_percent_post`l'yr {

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(treat)covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using table4,excel dec(2)  
 
rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using table4,excel dec(2) 

}
}
}

*Table 5
preserve
keep if year == 2010 

forv i = 1(1)1 {
forv l = 0(1)7 {
 
foreach y of varlist avg_was_post`l'yr was_percent_post`l'yr {

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(treat)covs(age maori disable full decile science business provider7001-provider7008 cohort2008)
outreg2 using table5,excel dec(2)  
 
rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008)
outreg2 using table5,excel dec(2) 

}
}
}
restore

*Table 6
forv i = 1(1)1 {
forv l = 0(1)5 {

foreach y of varlist loan_bal_post`l'yr {


rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using table6 ,excel dec(2) 

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using table6,excel dec(2) 

}
}
}

* Left Panel, female studnets assessed in 2010
preserve
keep if year == 2010 

forv i = 1(1)1 {
forv l = 0(1)7 {
 
foreach y of varlist loan_bal_post`l'yr {

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(treat)covs(age maori disable full decile science business provider7001-provider7008 cohort2008)
outreg2 using table6,excel dec(2)  
 
rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008)
outreg2 using table6,excel dec(2) 

}
}
}
restore
